package com.fxd.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @auther fuxudong
 * @date 2021/2/5 - 11:10
 */
public class SysExceptionResolver implements HandlerExceptionResolver {
    /**
     * 处理异常业务逻辑
     *
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o：handler,当前处理器对象
     * @param e：抛出的SysException对象
     * @return
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        //获取到异常对象
        SysException ex = null;
        if (e instanceof SysException) {
            ex = (SysException) e;
        } else {
            ex=new SysException("正在维护");
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("errormsg",ex.getMessage());
        mv.setViewName("error");
        return mv;
    }
}
